package com.xc.xcoj.judge;

import com.xc.xcoj.judge.codesandbox.model.JudgeInfo;
import com.xc.xcoj.judge.strategy.*;
import com.xc.xcoj.model.entity.QuestionSubmit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 判题管理（简化调用）
 */
@Service
public class JudgeManager {


    @Value("${codesandbox.languageType:java}")
    private String languageType;
    /**
     * 执行判题
     *
     * @param judgeContext
     * @return
     */
    public JudgeInfo doJudge(JudgeContext judgeContext) {
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        String language = questionSubmit.getLanguage();
//        JudgeStrategy judgeStrategy ;
//        if ("java".equals(language)) {
//            judgeStrategy = new JavaLanguageJudgeStrategy();
//        }

        //todo 24/10/20 策略优化
//        JudgeStrategy judgeStrategy = JudgeStrategyFactory.getIntance(languageType);
        //  24/10/20 也可以前端传过来
        JudgeStrategy judgeStrategy = JudgeStrategyFactory.getIntance(language);
        return judgeStrategy.doJudge(judgeContext);
    }

}
